package de.hypoport.einarbeitung.scrumspirit.persistence.genericdao.jpa2;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 * Convenience base class for JPA DAOs using the default (no unitName specified)
 * entity manager. To use, extend it in DAO classes.
 * 
 * @param <K>
 *            The primary key class of the entity, e.g. Long.
 * @param <E>
 *            The entity class the DAO persists, e.g. Person.
 */
public class Jpa2DaoImpl<K, E> extends AbstractJpa2Dao<K, E> implements
        Jpa2Dao<K, E> {
    @PersistenceContext
    protected EntityManager entityManager;

	protected boolean needTransaction;

    /** Make a new instance, automatically determining the entity class. */
    public Jpa2DaoImpl() {
        super();
    }

    /**
	 * Make a new instance, specifying the entity class.
	 * 
	 * @param entityClass
	 *            The entity class to manage.
	 */
    public Jpa2DaoImpl(Class<E> entityClass) {
        super(entityClass);
    }

    @Override
    public EntityManager getEntityManager() {
        return entityManager;
    }

    @Override
    public void setEntityManager(EntityManager entityManager) {
        this.entityManager = entityManager;
    }

	@Override
	public void setNeedTransaction(boolean needTransaction) {
		this.needTransaction = needTransaction;
	}

	@Override
	public boolean isNeedTransaction() {
		return this.needTransaction;
	}
}
